<!--我的页面-->
<script setup>

  import router from "../router/index.js";
  import {get,post} from '../util/Request.js'
  import {Toast} from "tdesign-mobile-vue";

  const login=()=>{
    router.push("/login")
  }

  const register=()=>{
    router.push("/register")
  }

  const user=JSON.parse(localStorage.getItem("user"))

  const loginOut=()=>{
    get("/tbUser/logout").then(r => {
      if (r.code == 0) {
        Toast(r.data)
        localStorage.removeItem("user")
        localStorage.removeItem("token")
        window.location.reload()
      } else {
        Toast(r.data)
        // localStorage.removeItem("user")
        // localStorage.removeItem("token")
        // window.location.reload()
      }
    })
  }

  const findMeBook=()=>{
    console.log(user.statu)
    router.push("/sc")
  }

  const allBook=()=>{
    router.push("/allBook")
  }

  const addBook=()=>{
    router.push("/addBook")
  }

  const updateBook=()=>{
    router.push("/updateBook")
  }


</script>

<template>
  <div>
    <h1>我的</h1>
  </div>

  <div v-if="user!=undefined && user!=null" style="flex-wrap: wrap;display: flex">
    <div class="avatar-demo" style="margin-left: 15%">
      <t-avatar
          class="avatar-example--large"
          shape="circle"
          size="large"
          image="https://tdesign.gtimg.com/mobile/demos/avatar1.png"
          alt="示例图片"
      ></t-avatar>
    </div>


    <div style="margin-top: -4%;margin-left: 4%">
      <h2 style="margin: 0 0;margin-top: 28%">{{user.name}}</h2>
      <h5 style="margin: 0 0">{{user.phone}}</h5>
    </div>

  </div>

  <div v-if="user!=undefined && user!=null"  @click="findMeBook">
    <h1>我的图书</h1>
  </div>
  <div v-if="user?.statu == 1" @click="allBook">
    <h1>所有图书</h1>
  </div>
  <div v-if="user?.statu == 1" @click="addBook">
    <h1>创建图书</h1>
  </div>
  <div v-if="user?.statu == 1" @click="updateBook">
    <h1>修改图书</h1>
  </div>

  <div v-if="user==undefined && user==null" @click="login">
    <h1>登录</h1>
  </div>
  <div v-if="user==undefined && user==null" @click="register">
    <h1>注册</h1>
  </div>
  <div v-if="user!=undefined && user!=null" @click="loginOut">
    <h1>退出</h1>
  </div>
</template>

<style scoped>

</style>